Parse.Cloud.define('getQlMemberInfo', async (req, res) => {
  const user = req.user
  if (!user) {
    res.error('请先授权登录')
  }
  try {
    const findMember = new Parse.Query('QlMember').equalTo('user', user).first()
    const findAccount = new Parse.Query('QlAccount').equalTo('user', user).first()
    const freeCountConfig = Parse.Config.get()
    const member = await findMember
    const account = await findAccount
    const config = await freeCountConfig
    res.success({
      memberId: member.id,
      headimgurl: member.get('headimgurl'),
      nickname: member.get('nickname'),
      freeCount: account.get('freeCount'),
      totalFreeCount: config.get('freeCount'),
      endTime: account.get('endTime'),
      vipId: account.get('vip') && account.get('vip').id
    })
  } catch (err) {
    console.log(err)
    res.error(err.message)
  }
})
